package com.xia;

import java.util.*;

public class InstrumentedHashSet<E> extends HashSet<E> {

    private int addCount = 0;

    public InstrumentedHashSet() {
    }

    public InstrumentedHashSet(int initialCapacity, float loadFactor) {
        super(initialCapacity, loadFactor);
    }

    @Override
    public boolean add(E e) {
        addCount++;
        return super.add(e);
    }

    @Override
    public boolean addAll(Collection<? extends E> c) {
        addCount  += c.size();
        return super.addAll(c);
    }


    public int getAddCount() {
        return addCount;
    }

    public static void main(String[] args) {
        InstrumentedHashSet<String> strings = new InstrumentedHashSet<>();
        strings.addAll(Arrays.asList("S","B","A"));
        System.out.println(strings.getAddCount());
        Collection collection = new ArrayDeque();
        Set<String> set = new HashSet<>();
    }
}
